package com.ricky.onlineShop.controller.trading;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ricky.onlineShop.serviceBus.trading.TradingOrderServiceBus;
import com.ricky.onlineShop.shop.trading.pojo.TradingOrder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ricky.common.annotation.Log;
import com.ricky.common.core.controller.BaseController;
import com.ricky.common.core.domain.AjaxResult;
import com.ricky.common.enums.BusinessType;
import com.ricky.common.utils.poi.ExcelUtil;
import com.ricky.common.core.page.TableDataInfo;

/**
 * 网店订单Controller
 *
 * @author ricky
 * @Date 2024-07-08
 */
@RestController
@RequestMapping("/onlineShop/tradingOrder")
public class TradingOrderController extends BaseController
{
    @Autowired
    private TradingOrderServiceBus tradingOrderServiceBus;

    /**
     * 查询网店订单列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TradingOrder tradingOrder)
    {
        startPage();
        List<TradingOrder> list = tradingOrderServiceBus.selectTradingOrderList(tradingOrder);
        return getDataTable(list);
    }

    /**
     * 查询个人网店订单列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:list')")
    @GetMapping("/myList")
    public TableDataInfo myList(TradingOrder tradingOrder)
    {
        startPage();
        List<TradingOrder> list = tradingOrderServiceBus.selectMyTradingOrderList(tradingOrder);
        return getDataTable(list);
    }

    /**
     * 导出网店订单列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:export')")
    @Log(title = "网店订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TradingOrder tradingOrder)
    {
        List<TradingOrder> list = tradingOrderServiceBus.selectTradingOrderList(tradingOrder);
        ExcelUtil<TradingOrder> util = new ExcelUtil<TradingOrder>(TradingOrder.class);
        util.exportExcel(response, list, "网店订单数据");
    }

    /**
     * 获取网店订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tradingOrderServiceBus.selectTradingOrderById(id));
    }

    /**
     * 新增网店订单
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:add')")
    @Log(title = "网店订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradingOrder tradingOrder)
    {
        return toAjax(tradingOrderServiceBus.insertTradingOrder(tradingOrder));
    }

    /**
     * 修改网店订单
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:edit')")
    @Log(title = "网店订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradingOrder tradingOrder)
    {
        return toAjax(tradingOrderServiceBus.updateTradingOrder(tradingOrder));
    }

    /**
     * 删除网店订单
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:remove')")
    @Log(title = "网店订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tradingOrderServiceBus.deleteTradingOrderByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('onlineShop:tradingOrder:remove')")
    @Log(title = "网店订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteTradingOrderById/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(tradingOrderServiceBus.deleteTradingOrderById(id));
    }
}
